Skip to content

Hexagon: Add libcall declarations for special memcpy #144975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 20, 2025

HexagonSelectionDAGInfo was bypassing the ordinary RuntimeLibcallInfo
handling for this case, so define a libcall for it and use it.

@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-backend-hexagon

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

HexagonSelectionDAGInfo was bypassing the ordinary RuntimeLibcallInfo
handling for this case, so define a libcall for it and use it.


Full diff: https://github.com/llvm/llvm-project/pull/144975.diff

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+6)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+4)
  • (modified) llvm/lib/Target/Hexagon/HexagonSelectionDAGInfo.cpp (+6-4)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 71efecdf082af..2efe823a760db 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -368,6 +368,9 @@ def AEABI_MEMCLR : RuntimeLibcall;
 def AEABI_MEMCLR4 : RuntimeLibcall;
 def AEABI_MEMCLR8 : RuntimeLibcall;
 
+// Hexagon calls
+def HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES : RuntimeLibcall;
+
 //--------------------------------------------------------------------
 // Define implementation default libcalls
 //--------------------------------------------------------------------
@@ -1247,6 +1250,9 @@ def __hexagon_fast2_sqrtf : RuntimeLibcallImpl<SQRT_F32>;
 // This is the only fast library function for sqrtd.
 def __hexagon_fast2_sqrtdf2 : RuntimeLibcallImpl<SQRT_F64>;
 
+def __hexagon_memcpy_likely_aligned_min32bytes_mult8bytes
+    : RuntimeLibcallImpl<HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES>;
+
 //===----------------------------------------------------------------------===//
 // Mips16 Runtime Libcalls
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 5fccb23e6c5ff..873ee6b509e2d 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -616,6 +616,10 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
       setLibcallImpl(RTLIB::SQRT_F32, RTLIB::__hexagon_fast2_sqrtf);
     else
       setLibcallImpl(RTLIB::SQRT_F32, RTLIB::__hexagon_sqrtf);
+
+    setLibcallImpl(
+        RTLIB::HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES,
+        RTLIB::__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes);
   }
 
   if (TT.getArch() == Triple::ArchType::msp430)
diff --git a/llvm/lib/Target/Hexagon/HexagonSelectionDAGInfo.cpp b/llvm/lib/Target/Hexagon/HexagonSelectionDAGInfo.cpp
index 1b724e8fcae91..610a81fe45c2f 100644
--- a/llvm/lib/Target/Hexagon/HexagonSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonSelectionDAGInfo.cpp
@@ -41,18 +41,20 @@ SDValue HexagonSelectionDAGInfo::EmitTargetCodeForMemcpy(
   Entry.Node = Size;
   Args.push_back(Entry);
 
-  const char *SpecialMemcpyName =
-      "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes";
+  const char *SpecialMemcpyName = TLI.getLibcallName(
+      RTLIB::HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES);
   const MachineFunction &MF = DAG.getMachineFunction();
   bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls();
   unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0;
 
+  CallingConv::ID CC = TLI.getLibcallCallingConv(
+      RTLIB::HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES);
+
   TargetLowering::CallLoweringInfo CLI(DAG);
   CLI.setDebugLoc(dl)
       .setChain(Chain)
       .setLibCallee(
-          TLI.getLibcallCallingConv(RTLIB::MEMCPY),
-          Type::getVoidTy(*DAG.getContext()),
+          CC, Type::getVoidTy(*DAG.getContext()),
           DAG.getTargetExternalSymbol(
               SpecialMemcpyName, TLI.getPointerTy(DAG.getDataLayout()), Flags),
           std::move(Args))

@androm3da androm3da requested a review from aankit-ca June 20, 2025 02:58
Copy link
Contributor

@aankit-ca aankit-ca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from bdbc320 to 8fec74a Compare June 23, 2025 13:27
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from a845b0e to 2a403de Compare June 23, 2025 13:27
@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from 8fec74a to 6bfbefe Compare June 25, 2025 12:42
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from 2a403de to 4632467 Compare June 25, 2025 12:42
@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from 6bfbefe to c18ce19 Compare June 27, 2025 07:31
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from 4632467 to d3f44e8 Compare June 27, 2025 07:31
Copy link
Contributor Author

arsenm commented Jun 27, 2025

Merge activity

  • Jun 27, 8:33 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 27, 8:44 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 27, 8:46 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from c18ce19 to 3271772 Compare June 27, 2025 08:41
Base automatically changed from users/arsenm/arm/add-libcall-definitions-eabi-memory-functions to main June 27, 2025 08:43
HexagonSelectionDAGInfo was bypassing the ordinary RuntimeLibcallInfo
handling for this case, so define a libcall for it and use it.
@arsenm arsenm force-pushed the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch from d3f44e8 to 944736b Compare June 27, 2025 08:44
@arsenm arsenm merged commit f38773e into main Jun 27, 2025
5 of 7 checks passed
@arsenm arsenm deleted the users/arsenm/hexagon/add-libcall-definitions-special-memcpy branch June 27, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants